package com.yst.feign1.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {

    /**
     * feign调用异常
     */
    @ResponseBody
    @ExceptionHandler(value =FeignFailResponseException.class)
    public HttpResult feignRequestExceptionHandler(FeignFailResponseException e){
        log.error("未知异常！原因是:",e);
        return HttpResult.error(e.getCode(),e.getMsg());
    }

    /**
     * 处理其他异常
     */
    @ResponseBody
    @ExceptionHandler(value =Exception.class)
    public HttpResult exceptionHandler(Exception e){
        log.error("未知异常！原因是:",e);
        return HttpResult.error(500,e.getMessage());
    }
}
